/*
 * Copyright 2008 - 2010 Lars Heuer (heuer[at]semagia.com). All rights reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.semagia.atomico.server.utils;

import java.net.URI;

import com.semagia.atomico.server.dm.ICollectionInfo;
import com.semagia.atomico.server.dm.IFragmentInfo;
import com.semagia.atomico.server.dm.ISnapshotInfo;

/**
 * 
 * 
 * @author Lars Heuer (heuer[at]semagia.com) <a href="http://www.semagia.com/">Semagia</a>
 */
public final class LinkUtils {

    private LinkUtils() {
        // noop.
    }

    /**
     * Returns a link to the provided fragment.
     *
     * @param info The fragment.
     * @return A link to the provided fragment.
     */
    public static URI linkTo(final URI baseURI, final ICollectionInfo collInfo,
            final IFragmentInfo info) {
        return linkToFragments(baseURI, collInfo).resolve(info.getFragmentId());
    }

    /**
     * 
     *
     * @param baseURI
     * @param collInfo
     * @param info
     * @return
     */
    public static URI linkTo(final URI baseURI, final ICollectionInfo collInfo,
            final ISnapshotInfo info) {
        return linkToSnapshots(baseURI, collInfo).resolve(info.getSnapshotId());
    }

    /**
     * Returns the URI for the provided collection.
     *
     * @param baseURI
     * @param info The collection.
     * @return A URI to the collection.
     */
    public static URI linkToCollection(final URI baseURI, ICollectionInfo info) {
        return baseURI.resolve("./" + info.getCollectionId() + "/");
    }

    /**
     * Returns a link to the snapshots feed.
     *
     * @param baseURI
     * @param info The collection.
     * @return A URI to the snapshot feed.
     */
    public static URI linkToSnapshots(URI baseURI, ICollectionInfo collInfo) {
        return linkToCollection(baseURI, collInfo).resolve("./snapshots/");
    }

    /**
     * Returns a link to the fragments feed.
     *
     * @param baseURI
     * @param info The collection.
     * @return A URI to the fragments feed.
     */
    public static URI linkToFragments(URI baseURI, ICollectionInfo collInfo) {
        return linkToCollection(baseURI, collInfo).resolve("./fragments/");
    }
}
